﻿using Abp.Application.Services;
using God.ShoppingWebApi.DTO;
using God.ShoppingWebApi.Entities;
using God.ShoppingWebApi.IService;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace God.ShoppingWebApi.WebAdmin
{
    /// <summary>
    /// 角色权限
    /// </summary>
    public class AdminRolePermissionService : ApplicationService, IAdminRolePermissionService
    {

        IRepository<RolePermission, Guid> _roleper;
        public AdminRolePermissionService(IRepository<RolePermission, Guid> roleper)
        {
            _roleper = roleper;
        }
        /// <summary>
        /// 角色权限添加
        /// </summary>
        /// <param name="permission"></param>
        /// <returns></returns>
        [Route("api/rolepermissionAdd")]
        public async Task AddAsync(RolePermissionDTO permission)
        {
            var a = new RolePermission();
            a.RoleId = permission.RoleId;
            a.PermissionId = permission.PermissionId;
            await _roleper.InsertAsync(a);
        }
        [Route("api/rolepermissionDel")]
        /// <summary>
        /// 角色权限删除
        /// </summary>
        /// <param name="gu"></param>
        /// <returns></returns>
        public async Task DeleteAsync(Guid gu)
        {
            await _roleper.DeleteAsync(gu);
        }
        [HttpGet]
        [Route("api/rolepermissionShow")]
        /// <summary>
        /// 角色权限显示板
        /// </summary>
        /// <returns></returns>
        public async Task<List<RolePermissionDTO>> GetListAsync()
        {
            //var str = await _roleper.GetListAsync();

            //return ObjectMapper.Map<List<RolePermission>, List<RolePermissionDTO>>(str);
            var str = (from x in await _roleper.GetListAsync()
                       select new RolePermissionDTO
                       {
                           Id = x.Id,
                           RoleId = x.RoleId,
                           PermissionId = x.PermissionId,
                    Create_time=x.Create_time
                       });
            return str.ToList();
        }


 
    }
}
